package com.iplant.ams.service.po.dms.maintenance;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.iplant.ams.service.basicenum.dms.DMSItemTaskStatus;
import com.iplant.ams.service.basicenum.dms.record.DMSItemRecordType;
import com.iplant.ams.service.po.dms.fault.DMSFaultBaseBPM;
import com.iplant.base.po.BasePO;
import com.iplant.base.po.enums.DBSchemas;
import com.iplant.base.utils.annotation.condition.DBCondition;
import com.iplant.base.utils.annotation.field.DBField;
import com.iplant.base.utils.annotation.join.DBJoin;
import com.iplant.base.utils.annotation.join.multi.DBJoinMulti;
import com.iplant.base.utils.annotation.po.DBBasePO;
import com.iplant.base.utils.general.StringUtils;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;

/**
 * 设备履历
 *
 * @author Femi
 * 2023-11-29 09:20:21
 */
@DBBasePO(TableName = "dms_maintenance_item_record", Name = false,Active = false,
        Schemas = DBSchemas.AMS, CheckName = {"Code"}, CodePrefix
        = "DMIR-{yyMM}",   CodeAuto = true)
public class DMSMaintenanceItemRecord extends BasePO implements Serializable {
    private static final long serialVersionUID = 1L;
    @DBField
    @DBCondition
    public int TaskItemID=0;

    @DBField
    @DBCondition
    public int TaskID=0;

    /**
     * 设备ID
     **/
    @DBField(CheckValue = true)
    @DBCondition
    public int DeviceID = 0;

//    @DBJoin(name = "AssetInfoID", tableName = "dms_device_ledger", tableAsName = "dms_device_ledger1", Schemas =
//            DBSchemas.AMS,
//            MainTableField = "DeviceID")

    @DBJoinMulti(Name = "AssetInfoID", TableName = "dms_device_ledger", Schemas = DBSchemas.AMS, MainTableField =
            "DeviceID")
    public int AssetInfoID = 0;

    /**
     * 设备名称
     **/
//    @DBJoin(name = "Name", tableName = "ams_asset_list", tableAsName = "ams_asset_list1", Schemas = DBSchemas.AMS,
//            JoinIndex = 2,
//            ConditionalJoin = "dms_device_ledger1.AssetInfoID=ams_asset_list1.ID")

    @DBJoinMulti(Name = "Name", TableName = "dms_device_ledger", Schemas = DBSchemas.AMS, MainTableField =
            "DeviceID")
    public String DeviceName = "";
    /**
     * 设备编码
     **/
//    @DBJoin(name = "Code", tableName = "ams_asset_list", tableAsName = "ams_asset_list1", Schemas = DBSchemas.AMS,
//            JoinIndex = 2,
//            ConditionalJoin = "dms_device_ledger1.AssetInfoID=ams_asset_list1.ID")

    @DBJoinMulti(Name = "Code", TableName = "dms_device_ledger", Schemas = DBSchemas.AMS, MainTableField =
            "DeviceID")
    public String DeviceCode = "";


    /**
     * 构型ID
     **/
    @DBField
    @DBCondition
    public int ConfigurationID = 0;
    /**
     * 构型名称
     **/
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "dms_configuration", tableAsName = "dms_configuration1", Schemas = DBSchemas.AMS,
            MainTableField = "ConfigurationID")
    public String ConfigurationName = "";
    @DBJoin(name = "Code", tableName = "dms_configuration", tableAsName = "dms_configuration1", Schemas = DBSchemas.AMS,
            MainTableField = "ConfigurationID")
    @DBCondition
    public String ConfigurationCode = "";

    /**
     * 项点名称  description 项点描述
     **/
    @DBField(CheckValue = true)
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    public String ItemName = "";

    /**
     * 项点编码
     */
    @DBField
    @DBCondition
    public String ItemCode = "";


    /**
     * 类型  1维护  2点检 3维修
     */
    @DBField(CheckValue = true)
    @DBCondition
    public int ItemType = 0;

    /**
     * 类型文本
     */
    public String ItemTypeString = "";

    /**
     * 等级，用于维修，维护的等级
     */
    @DBField
    @DBCondition
    public int ItemGrad = 0;

    /**
     * 执行人ID
     **/
    @DBField
    @DBCondition
    public int WorkerID = 0;
    /**
     * 执行人名称
     **/
    @DBJoinMulti(Name = "Name", TableName = "mbs_user", Schemas = DBSchemas.Basic, MainTableField =
            "WorkerID")
    public String WorkerName = "";
    /**
     * 执行时刻
     **/
    @DBCondition(CompareType = DBCondition.DBCompareType.geLe, ParamName = "WorkerTimeStart", ParamName2 = "WorkerTimeEnd")
    @DBField
    public Calendar WorkerTime = Calendar.getInstance();

    /**
     * 备注
     **/
    @DBField
    public String Remark = "";
    /**
     * 保养结果  0 未检  1 合格  2 不合格
     **/
    @DBCondition
    @DBField
    public int Result = 0;
    /**
     * 附件
     **/
    @DBField
    public List<String> ImageList = new ArrayList<>();


    public DMSMaintenanceItemRecord(){}

    public DMSMaintenanceItemRecord( DMSMaintenanceItemTask wDMSMaintenanceItemTask){
        TaskID=wDMSMaintenanceItemTask.TaskID;
        TaskItemID=wDMSMaintenanceItemTask.ID;
        Code=wDMSMaintenanceItemTask.Code;
        Name=wDMSMaintenanceItemTask.Name;
        ItemName=wDMSMaintenanceItemTask.MaintenanceItemName;
        ItemCode=wDMSMaintenanceItemTask.MaintenanceItemCode;
        Description=wDMSMaintenanceItemTask.MaintenanceItemDescription;
        DeviceID=wDMSMaintenanceItemTask.DeviceID;
        AssetInfoID=wDMSMaintenanceItemTask.AssetInfoID;
        DeviceName=wDMSMaintenanceItemTask.DeviceName;
        DeviceCode=wDMSMaintenanceItemTask.DeviceCode;
        ConfigurationID=wDMSMaintenanceItemTask.ConfigurationID;
        ConfigurationName=wDMSMaintenanceItemTask.ConfigurationName;
        ConfigurationCode=wDMSMaintenanceItemTask.ConfigurationCode;
        ItemType=wDMSMaintenanceItemTask.MaintenanceItemType;
        WorkerID=wDMSMaintenanceItemTask.WorkerID;
        WorkerName=wDMSMaintenanceItemTask.WorkerName;
        WorkerTime=wDMSMaintenanceItemTask.WorkerTime;
        Remark=wDMSMaintenanceItemTask.Remark;
        Result=wDMSMaintenanceItemTask.Result;
        ImageList=wDMSMaintenanceItemTask.ImageList;
    }

    public DMSMaintenanceItemRecord( DMSFaultBaseBPM wDMSFaultBaseBPM){
        TaskItemID=wDMSFaultBaseBPM.ID;
        Code=wDMSFaultBaseBPM.Code;
        Name=wDMSFaultBaseBPM.Name;
        ItemName=wDMSFaultBaseBPM.FaultDescribe;
        ItemCode=wDMSFaultBaseBPM.FaultCode;
        Description=wDMSFaultBaseBPM.FaultReason;
        DeviceID=wDMSFaultBaseBPM.DeviceID;
        AssetInfoID=wDMSFaultBaseBPM.AssetInfoID;
        DeviceName=wDMSFaultBaseBPM.DeviceName;
        DeviceCode=wDMSFaultBaseBPM.DeviceCode;
        ItemType=DMSItemRecordType.Repair.getValue();
        WorkerID=wDMSFaultBaseBPM.DisposerID;
        WorkerName=wDMSFaultBaseBPM.DisposerName;
        WorkerTime=wDMSFaultBaseBPM.CompletionTime;
        Remark=wDMSFaultBaseBPM.FaultRemark;
        Result=1;
        ImageList= StringUtils.splitList(wDMSFaultBaseBPM.NewFaultUrls,",");
    }

    @JsonProperty("TaskID")
    public int getTaskID() {
        return TaskID;
    }

    public void setTaskID(int taskID) {
        TaskID = taskID;
    }
    @JsonProperty("TaskItemID")
    public int getTaskItemID() {
        return TaskItemID;
    }

    public void setTaskItemID(int taskItemID) {
        TaskItemID = taskItemID;
    }

    @JsonProperty("DeviceID")
    public int getDeviceID() {
        return DeviceID;
    }

    public void setDeviceID(int deviceID) {
        DeviceID = deviceID;
    }

    @JsonProperty("AssetInfoID")
    public int getAssetInfoID() {
        return AssetInfoID;
    }

    public void setAssetInfoID(int assetInfoID) {
        AssetInfoID = assetInfoID;
    }

    @JsonProperty("DeviceName")
    public String getDeviceName() {
        return DeviceName;
    }

    public void setDeviceName(String deviceName) {
        DeviceName = deviceName;
    }

    @JsonProperty("DeviceCode")
    public String getDeviceCode() {
        return DeviceCode;
    }

    public void setDeviceCode(String deviceCode) {
        DeviceCode = deviceCode;
    }

    @JsonProperty("ConfigurationID")
    public int getConfigurationID() {
        return ConfigurationID;
    }

    public void setConfigurationID(int configurationID) {
        ConfigurationID = configurationID;
    }

    @JsonProperty("ConfigurationName")
    public String getConfigurationName() {
        return ConfigurationName;
    }

    public void setConfigurationName(String configurationName) {
        ConfigurationName = configurationName;
    }

    @JsonProperty("ConfigurationCode")
    public String getConfigurationCode() {
        return ConfigurationCode;
    }

    public void setConfigurationCode(String configurationCode) {
        ConfigurationCode = configurationCode;
    }


    @JsonProperty("ItemName")
    public String getItemName() {
        return ItemName;
    }

    public void setItemName(String itemName) {
        ItemName = itemName;
    }

    @JsonProperty("ItemCode")
    public String getItemCode() {
        return ItemCode;
    }

    public void setItemCode(String itemCode) {
        ItemCode = itemCode;
    }

    @JsonProperty("ItemType")
    public int getItemType() {
        return ItemType;
    }

    public void setItemType(int itemType) {
        ItemType = itemType;
    }

    @JsonProperty("ItemTypeString")
    public String getItemTypeString() {
        ItemTypeString = DMSItemRecordType.getEnumType(ItemType).getLabel();
        return ItemTypeString;
    }

    public void setItemTypeString(String itemTypeString) {
        ItemTypeString = itemTypeString;
    }

    @JsonProperty("ItemGrad")
    public int getItemGrad() {
        return ItemGrad;
    }

    public void setItemGrad(int itemGrad) {
        ItemGrad = itemGrad;
    }

    @JsonProperty("WorkerID")
    public int getWorkerID() {
        return WorkerID;
    }

    public void setWorkerID(int workerID) {
        WorkerID = workerID;
    }

    @JsonProperty("WorkerName")
    public String getWorkerName() {
        return WorkerName;
    }

    public void setWorkerName(String workerName) {
        WorkerName = workerName;
    }

    @JsonProperty("WorkerTime")
    public Calendar getWorkerTime() {
        return WorkerTime;
    }

    public void setWorkerTime(Calendar workerTime) {
        WorkerTime = workerTime;
    }


    @JsonProperty("Remark")
    public String getRemark() {
        return Remark;
    }

    public void setRemark(String remark) {
        Remark = remark;
    }

    @JsonProperty("Result")
    public int getResult() {
        return Result;
    }

    public void setResult(int result) {
        Result = result;
    }

    @JsonProperty("ImageList")
    public List<String> getImageList() {
        return ImageList;
    }

    public void setImageList(List<String> imageList) {
        ImageList = imageList;
    }


}
